package com.lennon.oauth.store.impl;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.lennon.oauth.domain.Token;
import com.lennon.oauth.store.AbstrctGeneratorUUID;
import com.lennon.oauth.store.ITokenStore;

public class TokenStore extends AbstrctGeneratorUUID implements ITokenStore{

	private Map<String/**token*/, Token/**clientInfo*/> tokenInfoHolder = new ConcurrentHashMap<String, Token>();
	
	@Override
	public String createUUIDToken(String clientId) {
		String token = generateCode();
		tokenInfoHolder.put(token, new Token(token, clientId, true));
		return token;
	}
	
	@Override
	public boolean isRightToken(String token) {
		if(token != null) {
			Token to = null;
			if(to != null && (to = tokenInfoHolder.get(token)) != null && to.isState()) {
				return true;
			}
		}
		return false;
	}
}
